package com.wquick.base.utils

import android.graphics.Bitmap


fun Bitmap.checkWhitePointRate(recycle: Boolean = true): Float {
    val snapshot = this
    // 像素点总数
    val pixelCount = (snapshot.width * snapshot.height).toFloat()
    var whitePixelCount = 0 // 白色像素点计数
    var otherPixelCount = 0 // 其他颜色像素点计数
    // 遍历 bitmap 像素点
    for (x in 0 until snapshot.width) {
        for (y in 0 until snapshot.height) {
            // 计数 其实记录一种就可以
            if (snapshot.getPixel(x, y) == -1) {
                whitePixelCount++
            } else {
                otherPixelCount++
            }
        }
    }
    // 回收 bitmap
    if (recycle) snapshot.recycle()

    if (whitePixelCount == 0) {
        return 0f
    }

    // 计算白色像素点占比 （计算其他颜色也一样）
    val percentage: Float = whitePixelCount / pixelCount * 100
    // 如果超过阈值 触发白屏提醒
    if (percentage > 95) {

    }
    return percentage
}
